Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

benchmark

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benchmark

A benchmarking library that supports high-resolution timers & returns statistically significant results.

  • 2.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
331K
increased by32.41%
Maintainers
2
Weekly downloads
 
Created

What is benchmark?

The 'benchmark' npm package is a library for benchmarking JavaScript code. It provides a simple and flexible API to measure the performance of code snippets, allowing developers to compare the speed of different implementations and optimize their code.

What are benchmark's main functionalities?

Basic Benchmarking

This feature allows you to create a suite of benchmarks to compare the performance of different code snippets. The example demonstrates how to add tests, attach listeners for cycle and completion events, and run the suite asynchronously.

const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;

// add tests
suite.add('RegExp#test', function() {
  /o/.test('Hello World!');
})
.add('String#indexOf', function() {
  'Hello World!'.indexOf('o') > -1;
})
// add listeners
.on('cycle', function(event) {
  console.log(String(event.target));
})
.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });

Event Handling

This feature allows you to handle various events during the benchmarking process, such as 'start', 'cycle', 'complete', etc. The example shows how to attach event listeners to a benchmark suite.

const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;

suite.add('Example Test', function() {
  // code to benchmark
})
.on('start', function() {
  console.log('Benchmark started');
})
.on('complete', function() {
  console.log('Benchmark completed');
})
.run();

Customizing Benchmark Options

This feature allows you to customize various options for your benchmarks, such as the minimum number of samples. The example demonstrates how to set the 'minSamples' option for a benchmark test.

const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;

suite.add('Example Test', function() {
  // code to benchmark
}, {
  'minSamples': 100
})
.run();

Other packages similar to benchmark

Keywords

FAQs

Package last updated on 28 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc